import { ApiProperty } from '@nestjs/swagger';
import { Posts } from '../../posts/entities/post.entity';
import {
  Column,
  CreateDateColumn,
  Entity,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity('category')
export class Category {
  @ApiProperty({ description: '类型id' })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({ description: '类型名' })
  @Column({
    unique: true,
    comment: '类型名',
    length: 100,
    default: null,
  })
  name: string;

  @ApiProperty({ description: '文章' })
  @OneToMany(() => Posts, (post) => post.category)
  posts: Array<Posts>;

  @ApiProperty({ description: '创建时间' })
  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
  })
  createTime: Date;

  @ApiProperty({ description: '更新时间' })
  @UpdateDateColumn({
    type: 'timestamp',
    comment: '更新时间',
  })
  updateTime: Date;
}
